//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TableroCuadro.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
TableroCuadro::TableroCuadro():Tablero(30,2,30,2,2,2){
        leeFichero(TEXTURA_CUADRO);
        glGenTextures(1,&nomTextura);  //Generamos el nombre del objeto textura

}

void TableroCuadro::dibuja(){

        glEnable(GL_TEXTURE_2D);

        glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,7);
        GLfloat spec[] = {1.0,1.0,1.0,1.0};
        glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,spec);

        //Activamos el objeto de textura
        glBindTexture(GL_TEXTURE_2D,nomTextura);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,128,128,0,GL_RGBA,
        GL_UNSIGNED_BYTE,pixeles);

        glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

        for(int i=0;i<nC;i++){
                glLineWidth(1.0);
                //glBegin(GL_LINE_LOOP);
                glBegin(GL_POLYGON);
                for(int j=0; j<cara[i]->getVN();j++){
                        int iV=cara[i]->getIV(j);
                        int iN=cara[i]->getIN(j);
                        switch (j){
                                case 0:glTexCoord2f(1,1);break;
                                case 1:glTexCoord2f(0,1);break;
                                case 2:glTexCoord2f(0,0);break;
                                case 3:glTexCoord2f(1,0);break;
                        }
                        glNormal3f(normal[iN]->getX(), normal[iN]->getY(), normal[iN]->getZ());

                        glVertex3f(vertice[iV]->getX(), vertice[iV]->getY(), vertice[iV]->getZ());
                }
                glEnd();
        }

   glDisable(GL_TEXTURE_2D);
}